
import '../../network/http_entity.dart';

class ImageTextList {
  final List<ImageText> imageTextList;
  final int? pageCurrent;
  final int? pageSize;
  final int? total;
  final bool? hasNext;
  final int? pages;

  ImageTextList({
    required this.imageTextList,
    this.pageCurrent,
    this.pageSize,
    this.total,
    this.hasNext,
    this.pages,
  });

  factory ImageTextList.fromJson(List<dynamic> json, dynamic result) {
    HttpEntity httpEntity = result;
    List<ImageText> imageTexts = json.map<ImageText>((item) {
      List<String> mediaFileIds = (item['mediaFileIds'] as List<dynamic>).cast<String>();
      return ImageText(
        id: item['id'],
        title: item['title'],
        content: item['content'],
        mediaFileIds: mediaFileIds,
        pubId: item['pubId'],
        createTime: item['createTime'],

        // 其他属性...
      );
    }).toList();

    return ImageTextList(
      imageTextList: imageTexts,
        pageCurrent : httpEntity.oriData['pageCurrent'],
        pageSize : httpEntity.oriData['pageSize'],
        total : httpEntity.oriData['total'],
        hasNext : httpEntity.oriData['hasNext'],
        pages : httpEntity.oriData['pages']
      // 其他属性...
    );
  }


  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    if (imageTextList != null) {
      map['list'] = imageTextList?.map((v) => v.toJson()).toList();
    }
    map['pageCurrent'] = pageCurrent;
    map['pageSize'] = pageSize;
    map['total'] = total;
    map['hasNext'] = hasNext;
    map['pages'] = pages;
    return map;
  }
}

class ImageText {
  final int id;
  final String title;
  final String content;
  final int? pubId;
  final String? createTime;
  final List<String> mediaFileIds;

  ImageText({required this.id, required this.title, required this.content, required this.pubId, required this.mediaFileIds,required this.createTime});

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'content': content,
      'pub_id': pubId,
      'media_file_id': mediaFileIds,
      'create_time': createTime
    };
  }

  factory ImageText.fromJson(Map<String, dynamic> json) {
    return ImageText(
      id: json['id'],
      title: json['title'],
      content: json['content'],
      pubId: json['pub_id'],
      mediaFileIds: json['media_file_id'],
      createTime: json['create_time']
    );
  }
}
